package com.tom.architect02.mnbase.zarch;

/**
 * Added by Tom on 2024/05/16.
 * 迭代器模式，针对数组处理。
 *     @Override
 *     public Iterator iterator() {
 *         return new HuiIterator(array);
 *     }
 */
public class HuiIterator implements Iterator {
    private Object[] array;
    private int position;

    public HuiIterator(Object[] arr) {
        this.array = arr;
    }

    @Override
    public boolean hasNext() {
        return !(position > array.length - 1 || array[position] == null);
    }

    @Override
    public Object next() {
        Object e = array[position];
        position ++;
        return e;
    }
}
